<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @author : $Id$
 */
class Gold_Orderpreparation_Model_Observer 
{	        
    public function updateShipmentState(Varien_Event_Observer $observer)
    {
    	$order = $observer->getEvent()->getOrder();    	  
    	if (!$order)
    	{
    		return;
    	}
		Mage::helper('Orderpreparation')->setShipmentState($order);
    }
    
    
    public function shipmentStateAfterTrackSaved(Varien_Event_Observer $observer)
    {
    	$track = $observer->getEvent()->getTrack();
    	Mage::helper('Orderpreparation')->setShipmentState($track->getShipment()->getOrder())->save();
    }
    
    public function addVirtualShipmentGridColumn(Varien_Event_Observer $observer)
    {
    	$observer->getEvent()->getResource()->addVirtualGridColumn(
                'shipping_method',
                'sales/order',
                array('order_id' => 'entity_id'),
                'SUBSTR({{table}}.shipping_method,INSTR({{table}}.shipping_method,"_")+1)'
            );
    }
}
